<template>
  <div class="layout-route">
      <div class="card card-search">
          <el-form :model="queryParams" ref="queryForm" v-show="showSearch" inline label-width="100px">
                <el-form-item label="采购批次号" prop="contract_number">
                    <el-input v-model.trim="queryParams.contract_number" placeholder="请输入采购批次号" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item label="SPU" prop="spu">
                    <el-input v-model.trim="queryParams.spu" placeholder="请输入SPU" clearable size="small" style="width: 240px" @keyup.enter.native="handleQuery" />
                </el-form-item>
               <el-form-item label=" ">
                  <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
              </el-form-item>
          </el-form>
      </div>

      <div class="card">
          <el-row :gutter="10" class="mb8">
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
          </el-row>
          <el-table v-loading="loading" :data="tableData" border script>
              <el-table-column label="采购批次号" prop="contract_number" min-width="160" show-overflow-tooltip>
                <template slot-scope="scope">
                    <el-button type="text" @click="showListDialog(scope.row)">{{ scope.row.contract_number }}</el-button>
                </template>
              </el-table-column>
              <el-table-column label="采购单号" prop="purchase_code" min-width="160" show-overflow-tooltip></el-table-column>
              <el-table-column label="SPU" prop="spu" min-width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="产品图片" prop="product_images" min-width="100">
                    <template slot-scope="scope">
                        <ImageUploadImg v-model="scope.row.product_images" :readOnly="true"></ImageUploadImg>
                    </template>
                </el-table-column>
              <el-table-column label="下单数量" prop="total_order_nums" min-width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="当前在途" prop="on_travel_nums" min-width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="未发货数" prop="un_send_nums" min-width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="在库数量" prop="inventory_nums" min-width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="总交货数" prop="delivery_nums" min-width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="次品率" prop="defective_rate" min-width="120" show-overflow-tooltip></el-table-column>
          </el-table>
          <pagination v-show="total > 0" :total="total" :page.sync="pageInfo.page" :limit.sync="pageInfo.limit" @pagination="getList"></pagination>
      </div>
      <list-dialog v-model="listDialog.visible" v-if="listDialog.visible" :params="listDialog.data" @success="handleQuery"></list-dialog>
  </div>
</template>

<script>
import { countInventoryList } from '@/api/purchase'
import ListDialog from './components/DefectiveInfoListDialog.vue'
export default {
  name: 'CountInventoryList',
  components: {ListDialog},
  data() {
      return {
          // 遮罩层
          loading: true,
          // 显示搜索条件
          showSearch: true,
          // 总条数
          total: 0,
          // 表格数据
          tableData: [],
          pageInfo: {
              page: 1,
              limit: 10,
          },
          // 查询参数
          queryParams: {
            spu: undefined,
            contract_number: undefined,
          },
          listDialog: {
            visible: false,
            data: {}
          }
      }
  },
  created() {
      this.getList()
  },
  methods: {
    showListDialog(row) {
        this.listDialog.visible = true;
        this.listDialog.data = row
    },
      //列表
      getList() {
          this.loading = true
          const qyparams = {
              ...this.pageInfo,
              ...this.queryParams,
          }
          countInventoryList(qyparams)
              .then(response => {
                    // this.tableData = response.data
                  this.tableData = response.data.list
                  this.total = response.data.total
              })
              .finally(() => {
                  this.loading = false
              })
      },

      // 搜索按钮操作
      handleQuery() {
          this.pageInfo.page = 1
          this.getList()
      },

      // 重置按钮操作
      resetQuery() {
          this.resetForm('queryForm')

          this.handleQuery()
      },
  },
}
</script>
